<!DOCTYPE html>
<html id="docs" lang="en" class="">
	<head>
	<meta charset="utf-8">
<title>Managing Resources - Kubernetes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="../../../../images/favicon.png">
<link rel="stylesheet" type="text/css" href="../../../../css/base_fonts.css">
<link rel="stylesheet" type="text/css" href="../../../../css/styles.css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<link rel="stylesheet" type="text/css" href="../../../../css/callouts.css">
<link rel="stylesheet" type="text/css" href="../../../../css/custom-jekyll/tags.css">




<meta name="description" content="Managing Resources" />
<meta property="og:description" content="Managing Resources" />

<meta property="og:url" content="https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/" />
<meta property="og:title" content="Managing Resources - Kubernetes" />

<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="../../../../js/script.js"></script>
<script src="../../../../js/custom-jekyll/tags.js"></script>


	</head>
	<body>
		<div id="cellophane" onclick="kub.toggleMenu()"></div>

<header>
    <a href="../../../../index.html" class="logo"></a>

    <div class="nav-buttons" data-auto-burger="primary">
        <ul class="global-nav">
            
            
            <li><a href="../../../home.1">Documentation</a></li>
            
            <li><a href="../../../../blog/index.html">Blog</a></li>
            
            <li><a href="../../../../partners/index.html">Partners</a></li>
            
            <li><a href="../../../../community/index.html">Community</a></li>
            
            <li><a href="../../../../case-studies/index.html">Case Studies</a></li>
            
            
             <li>
                <a href="index.html#">
                    English <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="../../../../zh/index.html">中文 Chinese</a></li>
                
                    <li><a href="../../../../ko/index.html">한국어 Korean</a></li>
                
                </ul>
            </li>
         
            <li>
                <a href="index.html#">
                    v1.11 <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="https://kubernetes.io">v1.12</a></li>
                
                    <li><a href="../../../../index.html">v1.11</a></li>
                
                    <li><a href="https://v1-10.docs.kubernetes.io">v1.10</a></li>
                
                    <li><a href="https://v1-9.docs.kubernetes.io">v1.9</a></li>
                
                </ul>
            </li>
        </ul>
        
        <a href="../../../tutorials/kubernetes-basics/index.html" class="button" id="tryKubernetes" data-auto-burger-exclude>Try Kubernetes</a>
        <button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
    </div>

    <nav id="mainNav">
        <main data-auto-burger="primary">
        <div class="nav-box">
            <h3><a href="../../../tutorials/stateless-application/hello-minikube/index.html">Get Started</a></h3>
            <p>Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../home.1">Documentation</a></h3>
            <p>Learn how to use Kubernetes with the use of walkthroughs, samples, and reference documentation. You can even <a href="../../../../editdocs/index.html" data-auto-burger-exclude>help contribute to the docs</a>!</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../community/index.html">Community</a></h3>
            <p>If you need help, you can connect with other Kubernetes users and the Kubernetes authors, attend community events, and watch video presentations from around the web.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../blog/index.html">Blog</a></h3>
            <p>Read the latest news for Kubernetes and the containers space in general, and get technical how-tos hot off the presses.</p>
        </div>
        </main>
        <main data-auto-burger="primary">
        <div class="left">
            <h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
            <a href="https://github.com/kubernetes/kubernetes" class="button" data-auto-burger-exclude>View On Github</a>
        </div>

        <div class="right">
            <h5 class="github-invite">Explore the community</h5>
            <div class="social">
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>Twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
        </div>
        <div class="clear" style="clear: both"></div>
        </main>
    </nav>
</header>

		
		
		<section id="hero" class="light-text no-sub">
			









<h1>Concepts</h1>
<h5></h5>








<div id="vendorStrip" class="light-text">
	<ul>
		
		
		<li><a href="../../../home.1">DOCUMENTATION</a></li>
		
		
		<li><a href="../../../setup/index.html">SETUP</a></li>
		
		
		<li><a href="../../index.html" class="YAH">CONCEPTS</a></li>
		
		
		<li><a href="../../../tasks/index.html">TASKS</a></li>
		
		
		<li><a href="../../../tutorials/index.html">TUTORIALS</a></li>
		
		
		<li><a href="../../../reference.1">REFERENCE</a></li>
		
	</ul>
	<div id="searchBox">
		<input type="text" id="search" placeholder="Search" onkeydown="if (event.keyCode==13) window.location.replace('/docs/search/?q=' + this.value)" autofocus="autofocus">
	</div>
</div>

		</section>
		
		
<section id="deprecationWarning">
  <main>
    <div class="content deprecation-warning">
      <h3>
        Documentation for Kubernetes v1.11 is no longer actively maintained. The version you are currently viewing is a static snapshot.
        For up-to-date documentation, see the <a href="https://kubernetes.io/docs/home/">latest</a> version.
      </h3>
    </div>
  </main>
</section>


		<section id="encyclopedia">
			
<div id="docsToc">
     <div class="pi-accordion">
    	
        
        
        
        
        
         
             
                 
             
         
             
                 
             
         
             
                 
                          
                          
                 
             
         
             
         
             
         
             
         
             
         
             
         
         
        
        <a class="item" data-title="Concepts" href="../../index.html"></a>

	
	
		
		
	<div class="item" data-title="Overview">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="What is Kubernetes?" href="../../overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Kubernetes Components" href="../../overview/components.1"></a>

		
	
		
		
<a class="item" data-title="The Kubernetes API" href="../../overview/kubernetes-api/index.html"></a>

		
	
		
		
	<div class="item" data-title="Working with Kubernetes Objects">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Understanding Kubernetes Objects" href="../../overview/working-with-objects/kubernetes-objects.1"></a>

		
	
		
		
<a class="item" data-title="Names" href="../../../user-guide/identifiers"></a>

		
	
		
		
<a class="item" data-title="Namespaces" href="../../overview/working-with-objects/namespaces.1"></a>

		
	
		
		
<a class="item" data-title="Labels and Selectors" href="../../../user-guide/labels"></a>

		
	
		
		
<a class="item" data-title="Annotations" href="../../overview/working-with-objects/annotations.1"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Object Management Using kubectl">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Kubernetes Object Management" href="../../../tutorials/object-management-kubectl/object-management/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Kubernetes Objects Using Imperative Commands" href="../../../tutorials/object-management-kubectl/imperative-object-management-command/index.html"></a>

		
	
		
		
<a class="item" data-title="Imperative Management of Kubernetes Objects Using Configuration Files" href="../../../tutorials/object-management-kubectl/imperative-object-management-configuration/index.html"></a>

		
	
		
		
<a class="item" data-title="Declarative Management of Kubernetes Objects Using Configuration Files" href="../../../tutorials/object-management-kubectl/declarative-object-management-configuration/index.html"></a>

		
	

		</div>
	</div>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Compute, Storage, and Networking Extensions">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Cluster Administration Overview" href="../cluster-administration-overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Certificates" href="../certificates/index.html"></a>

		
	
		
		
<a class="item" data-title="Cloud Providers" href="../cloud-providers/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Resources" href="index.html"></a>

		
	
		
		
<a class="item" data-title="Cluster Networking" href="../../../admin/networking"></a>

		
	
		
		
<a class="item" data-title="Logging Architecture" href="../logging.1"></a>

		
	
		
		
<a class="item" data-title="Configuring kubelet Garbage Collection" href="../kubelet-garbage-collection/index.html"></a>

		
	
		
		
<a class="item" data-title="Federation" href="../federation/index.html"></a>

		
	
		
		
<a class="item" data-title="Proxies in Kubernetes" href="../proxies/index.html"></a>

		
	
		
		
<a class="item" data-title="Controller manager metrics" href="../controller-metrics/index.html"></a>

		
	
		
		
<a class="item" data-title="Installing Addons" href="../addons/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Kubernetes Architecture">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Nodes" href="../../../admin/node.1"></a>

		
	
		
		
<a class="item" data-title="Master-Node communication" href="../../architecture/master-node-communication/index.html"></a>

		
	
		
		
<a class="item" data-title="Concepts Underlying the Cloud Controller Manager" href="../../architecture/cloud-controller/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Extending Kubernetes">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Extending your Kubernetes Cluster" href="../../overview/extending/index.html"></a>

		
	
		
		
	<div class="item" data-title="Extending the Kubernetes API">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Extending the Kubernetes API with the aggregation layer" href="../../api-extension/apiserver-aggregation.1"></a>

		
	
		
		
<a class="item" data-title="Custom Resources" href="../../api-extension/custom-resources/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Compute, Storage, and Networking Extensions">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Network Plugins" href="../../../admin/network-plugins/index.html"></a>

		
	
		
		
<a class="item" data-title="Device Plugins" href="../device-plugins.1"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Service Catalog" href="../../service-catalog/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Containers">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Images" href="../../containers/images/index.html"></a>

		
	
		
		
<a class="item" data-title="Container Environment Variables" href="../../containers/container-environment-variables/index.html"></a>

		
	
		
		
<a class="item" data-title="Container Lifecycle Hooks" href="../../containers/container-lifecycle-hooks/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Workloads">
		<div class="container">
		
		
	
	
		
		
	<div class="item" data-title="Pods">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Pod Overview" href="../../workloads/pods/pod-overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Pods" href="../../../user-guide/pods/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Lifecycle" href="../../../user-guide/pod-states/index.html"></a>

		
	
		
		
<a class="item" data-title="Init Containers" href="../../abstractions/init-containers/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Preset" href="../../workloads/pods/podpreset/index.html"></a>

		
	
		
		
<a class="item" data-title="Disruptions" href="../../workloads/pods/disruptions/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Controllers">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="ReplicaSet" href="../../workloads/controllers/replicaset/index.html"></a>

		
	
		
		
<a class="item" data-title="ReplicationController" href="../../../user-guide/replication-controller/index.html"></a>

		
	
		
		
<a class="item" data-title="Deployments" href="../../workloads/controllers/deployment/index.html"></a>

		
	
		
		
<a class="item" data-title="StatefulSets" href="../../workloads/controllers/statefulset.md"></a>

		
	
		
		
<a class="item" data-title="DaemonSet" href="../../workloads/controllers/daemonset.1"></a>

		
	
		
		
<a class="item" data-title="Garbage Collection" href="../../workloads/controllers/garbage-collection/index.html"></a>

		
	
		
		
<a class="item" data-title="Jobs - Run to Completion" href="../../workloads/controllers/jobs-run-to-completion.1"></a>

		
	
		
		
<a class="item" data-title="CronJob" href="../../workloads/controllers/cron-jobs.1"></a>

		
	

		</div>
	</div>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Configuration">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Configuration Best Practices" href="../../configuration/overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Compute Resources for Containers" href="../../../user-guide/compute-resources/index.html"></a>

		
	
		
		
<a class="item" data-title="Assigning Pods to Nodes" href="../../../user-guide/node-selection/index.html"></a>

		
	
		
		
<a class="item" data-title="Taints and Tolerations" href="../../configuration/taint-and-toleration.1"></a>

		
	
		
		
<a class="item" data-title="Secrets" href="../../../user-guide/secrets.1"></a>

		
	
		
		
<a class="item" data-title="Organizing Cluster Access Using kubeconfig Files" href="../../configuration/organize-cluster-access-kubeconfig/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Priority and Preemption" href="../../configuration/pod-priority-preemption/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Services, Load Balancing, and Networking">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Services" href="../../../user-guide/services"></a>

		
	
		
		
<a class="item" data-title="DNS for Services and Pods" href="../../services-networking/dns-pod-service/index.html"></a>

		
	
		
		
<a class="item" data-title="Connecting Applications with Services" href="../../services-networking/connect-applications-service.1"></a>

		
	
		
		
<a class="item" data-title="Ingress" href="../../services-networking/ingress/index.html"></a>

		
	
		
		
<a class="item" data-title="Network Policies" href="../../services-networking/networkpolicies/index.html"></a>

		
	
		
		
<a class="item" data-title="Adding entries to Pod /etc/hosts with HostAliases" href="../../services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Storage">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Volumes" href="../../storage/volumes.1"></a>

		
	
		
		
<a class="item" data-title="Persistent Volumes" href="../../../user-guide/persistent-volumes/index.html"></a>

		
	
		
		
<a class="item" data-title="Storage Classes" href="../../storage/storage-classes.1"></a>

		
	
		
		
<a class="item" data-title="Dynamic Volume Provisioning" href="../../storage/dynamic-provisioning/index.html"></a>

		
	
		
		
<a class="item" data-title="Node-specific Volume Limits" href="../../storage/storage-limits/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Policies">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Resource Quotas" href="../../policy/resource-quotas/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Security Policies" href="../../../user-guide/pod-security-policy"></a>

		
	

		</div>
	</div>

		
	






     </div> 
    <button class="push-menu-close-button" onclick="kub.toggleToc()"></button>
</div> 

			<div id="docsContent">
				
<p><a href="../../../editdocs#docs/concepts/cluster-administration/manage-deployment.md" id="editPageButton">Edit This Page</a></p>

<h1>Managing Resources</h1>



<p>You&rsquo;ve deployed your application and exposed it via a service. Now what? Kubernetes provides a number of tools to help you manage your application deployment, including scaling and updating. Among the features that we will discuss in more depth are <a href="../../configuration/overview/index.html">configuration files</a> and <a href="../../../user-guide/labels">labels</a>.</p>









<ul id="markdown-toc">










<li><a href="index.html#organizing-resource-configurations">Organizing resource configurations</a></li>




<li><a href="index.html#bulk-operations-in-kubectl">Bulk operations in kubectl</a></li>




<li><a href="index.html#using-labels-effectively">Using labels effectively</a></li>




<li><a href="index.html#canary-deployments">Canary deployments</a></li>




<li><a href="index.html#updating-labels">Updating labels</a></li>




<li><a href="index.html#updating-annotations">Updating annotations</a></li>




<li><a href="index.html#scaling-your-application">Scaling your application</a></li>




<li><a href="index.html#in-place-updates-of-resources">In-place updates of resources</a></li>




<li><a href="index.html#disruptive-updates">Disruptive updates</a></li>




<li><a href="index.html#updating-your-application-without-a-service-outage">Updating your application without a service outage</a></li>




















<li><a href="index.html#what-s-next">What's next</a></li>



</ul>


<h2 id="organizing-resource-configurations">Organizing resource configurations</h2>

<p>Many applications require multiple resources to be created, such as a Deployment and a Service. Management of multiple resources can be simplified by grouping them together in the same file (separated by <code>---</code> in YAML). For example:</p>

<table class="includecode" id="nginx-app-yaml">
    <thead>
        <tr>
            <th>
                <a href="https://github.com/kubernetes/website/blob/master/content/en/docs/concepts/cluster-administration/nginx-app.yaml" download="nginx-app.yaml">
                    <code>nginx-app.yaml docs/concepts/cluster-administration</code>
                </a>
                <img src="../../../../images/copycode.svg" style="max-height:24px" onclick="copyCode('nginx-app-yaml')" title="Copy nginx-app.yaml to clipboard">
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Service<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>my-nginx-svc<span style="color:#bbb">
</span><span style="color:#bbb">  </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>type:<span style="color:#bbb"> </span>LoadBalancer<span style="color:#bbb">
</span><span style="color:#bbb">  </span>ports:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>-<span style="color:#bbb"> </span>port:<span style="color:#bbb"> </span><span style="color:#666">80</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selector:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb"></span>---<span style="color:#bbb">
</span><span style="color:#bbb"></span>apiVersion:<span style="color:#bbb"> </span>apps/v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Deployment<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>my-nginx<span style="color:#bbb">
</span><span style="color:#bbb">  </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>replicas:<span style="color:#bbb"> </span><span style="color:#666">3</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selector:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>matchLabels:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">  </span>template:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">    </span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">        </span>image:<span style="color:#bbb"> </span>nginx:<span style="color:#666">1.7</span>.<span style="color:#666">9</span><span style="color:#bbb">
</span><span style="color:#bbb">        </span>ports:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>-<span style="color:#bbb"> </span>containerPort:<span style="color:#bbb"> </span><span style="color:#666">80</span><span style="color:#bbb">
</span><span style="color:#bbb"></span></code></pre></div>  </td>
        </tr>
    </tbody>
</table>

<p>Multiple resources can be created the same way as a single resource:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f https://k8s.io/docs/concepts/cluster-administration/nginx-app.yaml
service <span style="color:#b44">&#34;my-nginx-svc&#34;</span> created
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> created</code></pre></div>
<p>The resources will be created in the order they appear in the file. Therefore, it&rsquo;s best to specify the service first, since that will ensure the scheduler can spread the pods associated with the service as they are created by the controller(s), such as Deployment.</p>

<p><code>kubectl create</code> also accepts multiple <code>-f</code> arguments:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f https://k8s.io/docs/concepts/cluster-administration/nginx/nginx-svc.yaml -f https://k8s.io/docs/concepts/cluster-administration/nginx/nginx-deployment.yaml</code></pre></div>
<p>And a directory can be specified rather than or in addition to individual files:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f https://k8s.io/docs/concepts/cluster-administration/nginx/</code></pre></div>
<p><code>kubectl</code> will read any files with suffixes <code>.yaml</code>, <code>.yml</code>, or <code>.json</code>.</p>

<p>It is a recommended practice to put resources related to the same microservice or application tier into the same file, and to group all of the files associated with your application in the same directory. If the tiers of your application bind to each other using DNS, then you can then simply deploy all of the components of your stack en masse.</p>

<p>A URL can also be specified as a configuration source, which is handy for deploying directly from configuration files checked into github:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f https://raw.githubusercontent.com/kubernetes/website/master/docs/concepts/cluster-administration/nginx-deployment.yaml
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> created</code></pre></div>
<h2 id="bulk-operations-in-kubectl">Bulk operations in kubectl</h2>

<p>Resource creation isn&rsquo;t the only operation that <code>kubectl</code> can perform in bulk. It can also extract resource names from configuration files in order to perform other operations, in particular to delete the same resources you created:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl delete -f https://k8s.io/docs/concepts/cluster-administration/nginx-app.yaml
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> deleted
service <span style="color:#b44">&#34;my-nginx-svc&#34;</span> deleted</code></pre></div>
<p>In the case of just two resources, it&rsquo;s also easy to specify both on the command line using the resource/name syntax:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl delete deployments/my-nginx services/my-nginx-svc</code></pre></div>
<p>For larger numbers of resources, you&rsquo;ll find it easier to specify the selector (label query) specified using <code>-l</code> or <code>--selector</code>, to filter resources by their labels:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl delete deployment,services -l <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> deleted
service <span style="color:#b44">&#34;my-nginx-svc&#34;</span> deleted</code></pre></div>
<p>Because <code>kubectl</code> outputs resource names in the same syntax it accepts, it&rsquo;s easy to chain operations using <code>$()</code> or <code>xargs</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get <span style="color:#a2f;font-weight:bold">$(</span>kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service<span style="color:#a2f;font-weight:bold">)</span>
NAME           CLUSTER-IP   EXTERNAL-IP   PORT<span style="color:#666">(</span>S<span style="color:#666">)</span>      AGE
my-nginx-svc   <span style="color:#666">10</span>.0.0.208   &lt;pending&gt;     <span style="color:#666">80</span>/TCP       0s</code></pre></div>
<p>With the above commands, we first create resources under <code>docs/concepts/cluster-administration/nginx/</code> and print the resources created with <code>-o name</code> output format
(print each resource as resource/name). Then we <code>grep</code> only the &ldquo;service&rdquo;, and then print it with <code>kubectl get</code>.</p>

<p>If you happen to organize your resources across several subdirectories within a particular directory, you can recursively perform the operations on the subdirectories also, by specifying <code>--recursive</code> or <code>-R</code> alongside the <code>--filename,-f</code> flag.</p>

<p>For instance, assume there is a directory <code>project/k8s/development</code> that holds all of the manifests needed for the development environment, organized by resource type:</p>

<pre><code>project/k8s/development
├── configmap
│   └── my-configmap.yaml
├── deployment
│   └── my-deployment.yaml
└── pvc
    └── my-pvc.yaml
</code></pre>

<p>By default, performing a bulk operation on <code>project/k8s/development</code> will stop at the first level of the directory, not processing any subdirectories. If we had tried to create the resources in this directory using the following command, we would have encountered an error:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f project/k8s/development
error: you must provide one or more resources by argument or filename <span style="color:#666">(</span>.json|.yaml|.yml|stdin<span style="color:#666">)</span></code></pre></div>
<p>Instead, specify the <code>--recursive</code> or <code>-R</code> flag with the <code>--filename,-f</code> flag as such:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f project/k8s/development --recursive
configmap <span style="color:#b44">&#34;my-config&#34;</span> created
deployment <span style="color:#b44">&#34;my-deployment&#34;</span> created
persistentvolumeclaim <span style="color:#b44">&#34;my-pvc&#34;</span> created</code></pre></div>
<p>The <code>--recursive</code> flag works with any operation that accepts the <code>--filename,-f</code> flag such as: <code>kubectl {create,get,delete,describe,rollout} etc.</code></p>

<p>The <code>--recursive</code> flag also works when multiple <code>-f</code> arguments are provided:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f project/k8s/namespaces -f project/k8s/development --recursive
namespace <span style="color:#b44">&#34;development&#34;</span> created
namespace <span style="color:#b44">&#34;staging&#34;</span> created
configmap <span style="color:#b44">&#34;my-config&#34;</span> created
deployment <span style="color:#b44">&#34;my-deployment&#34;</span> created
persistentvolumeclaim <span style="color:#b44">&#34;my-pvc&#34;</span> created</code></pre></div>
<p>If you&rsquo;re interested in learning more about <code>kubectl</code>, go ahead and read <a href="../../../user-guide/kubectl-overview.1">kubectl Overview</a>.</p>

<h2 id="using-labels-effectively">Using labels effectively</h2>

<p>The examples we&rsquo;ve used so far apply at most a single label to any resource. There are many scenarios where multiple labels should be used to distinguish sets from one another.</p>

<p>For instance, different applications would use different values for the <code>app</code> label, but a multi-tier application, such as the <a href="https://github.com/kubernetes/examples/tree/v1.11.3/guestbook/" target="_blank">guestbook example</a>, would additionally need to distinguish each tier. The frontend could carry the following labels:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">     </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">        </span>tier:<span style="color:#bbb"> </span>frontend</code></pre></div>
<p>while the Redis master and slave would have different <code>tier</code> labels, and perhaps even an additional <code>role</code> label:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">     </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">        </span>tier:<span style="color:#bbb"> </span>backend<span style="color:#bbb">
</span><span style="color:#bbb">        </span>role:<span style="color:#bbb"> </span>master</code></pre></div>
<p>and</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">     </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">        </span>tier:<span style="color:#bbb"> </span>backend<span style="color:#bbb">
</span><span style="color:#bbb">        </span>role:<span style="color:#bbb"> </span>slave</code></pre></div>
<p>The labels allow us to slice and dice our resources along any dimension specified by a label:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl create -f examples/guestbook/all-in-one/guestbook-all-in-one.yaml
$ kubectl get pods -Lapp -Ltier -Lrole
NAME                           READY     STATUS    RESTARTS   AGE       APP         TIER       ROLE
guestbook-fe-4nlpb             <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   frontend   &lt;none&gt;
guestbook-fe-ght6d             <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   frontend   &lt;none&gt;
guestbook-fe-jpy62             <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   frontend   &lt;none&gt;
guestbook-redis-master-5pg3b   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   backend    master
guestbook-redis-slave-2q2yf    <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   backend    slave
guestbook-redis-slave-qgazl    <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          1m        guestbook   backend    slave
my-nginx-divi2                 <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          29m       nginx       &lt;none&gt;     &lt;none&gt;
my-nginx-o0ef1                 <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          29m       nginx       &lt;none&gt;     &lt;none&gt;
$ kubectl get pods -lapp<span style="color:#666">=</span>guestbook,role<span style="color:#666">=</span>slave
NAME                          READY     STATUS    RESTARTS   AGE
guestbook-redis-slave-2q2yf   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          3m
guestbook-redis-slave-qgazl   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          3m</code></pre></div>
<h2 id="canary-deployments">Canary deployments</h2>

<p>Another scenario where multiple labels are needed is to distinguish deployments of different releases or configurations of the same component. It is common practice to deploy a <em>canary</em> of a new application release (specified via image tag in the pod template) side by side with the previous release so that the new release can receive live production traffic before fully rolling it out.</p>

<p>For instance, you can use a <code>track</code> label to differentiate different releases.</p>

<p>The primary, stable release would have a <code>track</code> label with value as <code>stable</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>frontend<span style="color:#bbb">
</span><span style="color:#bbb">     </span>replicas:<span style="color:#bbb"> </span><span style="color:#666">3</span><span style="color:#bbb">
</span><span style="color:#bbb">     </span>...<span style="color:#bbb">
</span><span style="color:#bbb">     </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">        </span>tier:<span style="color:#bbb"> </span>frontend<span style="color:#bbb">
</span><span style="color:#bbb">        </span>track:<span style="color:#bbb"> </span>stable<span style="color:#bbb">
</span><span style="color:#bbb">     </span>...<span style="color:#bbb">
</span><span style="color:#bbb">     </span>image:<span style="color:#bbb"> </span>gb-frontend:v3</code></pre></div>
<p>and then you can create a new release of the guestbook frontend that carries the <code>track</code> label with different value (i.e. <code>canary</code>), so that two sets of pods would not overlap:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">     </span>name:<span style="color:#bbb"> </span>frontend-canary<span style="color:#bbb">
</span><span style="color:#bbb">     </span>replicas:<span style="color:#bbb"> </span><span style="color:#666">1</span><span style="color:#bbb">
</span><span style="color:#bbb">     </span>...<span style="color:#bbb">
</span><span style="color:#bbb">     </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">        </span>tier:<span style="color:#bbb"> </span>frontend<span style="color:#bbb">
</span><span style="color:#bbb">        </span>track:<span style="color:#bbb"> </span>canary<span style="color:#bbb">
</span><span style="color:#bbb">     </span>...<span style="color:#bbb">
</span><span style="color:#bbb">     </span>image:<span style="color:#bbb"> </span>gb-frontend:v4</code></pre></div>
<p>The frontend service would span both sets of replicas by selecting the common subset of their labels (i.e. omitting the <code>track</code> label), so that the traffic will be redirected to both applications:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#bbb">  </span>selector:<span style="color:#bbb">
</span><span style="color:#bbb">     </span>app:<span style="color:#bbb"> </span>guestbook<span style="color:#bbb">
</span><span style="color:#bbb">     </span>tier:<span style="color:#bbb"> </span>frontend</code></pre></div>
<p>You can tweak the number of replicas of the stable and canary releases to determine the ratio of each release that will receive live production traffic (in this case, 3:1).
Once you&rsquo;re confident, you can update the stable track to the new application release and remove the canary one.</p>

<p>For a more concrete example, check the <a href="https://github.com/kelseyhightower/talks/tree/master/kubecon-eu-2016/demo#deploy-a-canary" target="_blank">tutorial of deploying Ghost</a>.</p>

<h2 id="updating-labels">Updating labels</h2>

<p>Sometimes existing pods and other resources need to be relabeled before creating new resources. This can be done with <code>kubectl label</code>.
For example, if you want to label all your nginx pods as frontend tier, simply run:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl label pods -l <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx <span style="color:#b8860b">tier</span><span style="color:#666">=</span>fe
pod <span style="color:#b44">&#34;my-nginx-2035384211-j5fhi&#34;</span> labeled
pod <span style="color:#b44">&#34;my-nginx-2035384211-u2c7e&#34;</span> labeled
pod <span style="color:#b44">&#34;my-nginx-2035384211-u3t6x&#34;</span> labeled</code></pre></div>
<p>This first filters all pods with the label &ldquo;app=nginx&rdquo;, and then labels them with the &ldquo;tier=fe&rdquo;.
To see the pods you just labeled, run:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods -l <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx -L tier
NAME                        READY     STATUS    RESTARTS   AGE       TIER
my-nginx-2035384211-j5fhi   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          23m       fe
my-nginx-2035384211-u2c7e   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          23m       fe
my-nginx-2035384211-u3t6x   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          23m       fe</code></pre></div>
<p>This outputs all &ldquo;app=nginx&rdquo; pods, with an additional label column of pods&rsquo; tier (specified with <code>-L</code> or <code>--label-columns</code>).</p>

<p>For more information, please see <a href="../../../user-guide/labels">labels</a> and <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#label">kubectl label</a>.</p>

<h2 id="updating-annotations">Updating annotations</h2>

<p>Sometimes you would want to attach annotations to resources. Annotations are arbitrary non-identifying metadata for retrieval by API clients such as tools, libraries, etc. This can be done with <code>kubectl annotate</code>. For example:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl annotate pods my-nginx-v4-9gw19 <span style="color:#b8860b">description</span><span style="color:#666">=</span><span style="color:#b44">&#39;my frontend running nginx&#39;</span>
$ kubectl get pods my-nginx-v4-9gw19 -o yaml
apiversion: v1
kind: pod
metadata:
  annotations:
    description: my frontend running nginx
...</code></pre></div>
<p>For more information, please see <a href="../../overview/working-with-objects/annotations.1">annotations</a> and <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#annotate">kubectl annotate</a> document.</p>

<h2 id="scaling-your-application">Scaling your application</h2>

<p>When load on your application grows or shrinks, it&rsquo;s easy to scale with <code>kubectl</code>. For instance, to decrease the number of nginx replicas from 3 to 1, do:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl scale deployment/my-nginx --replicas<span style="color:#666">=</span><span style="color:#666">1</span>
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> scaled</code></pre></div>
<p>Now you only have one pod managed by the deployment.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods -l <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
NAME                        READY     STATUS    RESTARTS   AGE
my-nginx-2035384211-j5fhi   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          30m</code></pre></div>
<p>To have the system automatically choose the number of nginx replicas as needed, ranging from 1 to 3, do:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl autoscale deployment/my-nginx --min<span style="color:#666">=</span><span style="color:#666">1</span> --max<span style="color:#666">=</span><span style="color:#666">3</span>
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> autoscaled</code></pre></div>
<p>Now your nginx replicas will be scaled up and down as needed, automatically.</p>

<p>For more information, please see <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#scale">kubectl scale</a>, <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#autoscale">kubectl autoscale</a> and <a href="../../../tasks/run-application/horizontal-pod-autoscale/index.html">horizontal pod autoscaler</a> document.</p>

<h2 id="in-place-updates-of-resources">In-place updates of resources</h2>

<p>Sometimes it&rsquo;s necessary to make narrow, non-disruptive updates to resources you&rsquo;ve created.</p>

<h3 id="kubectl-apply">kubectl apply</h3>

<p>It is suggested to maintain a set of configuration files in source control (see <a href="http://martinfowler.com/bliki/InfrastructureAsCode.html" target="_blank">configuration as code</a>),
so that they can be maintained and versioned along with the code for the resources they configure.
Then, you can use <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#apply"><code>kubectl apply</code></a> to push your configuration changes to the cluster.</p>

<p>This command will compare the version of the configuration that you&rsquo;re pushing with the previous version and apply the changes you&rsquo;ve made, without overwriting any automated changes to properties you haven&rsquo;t specified.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl apply -f docs/concepts/cluster-administration/nginx/nginx-deployment.yaml
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> configured</code></pre></div>
<p>Note that <code>kubectl apply</code> attaches an annotation to the resource in order to determine the changes to the configuration since the previous invocation. When it&rsquo;s invoked, <code>kubectl apply</code> does a three-way diff between the previous configuration, the provided input and the current configuration of the resource, in order to determine how to modify the resource.</p>

<p>Currently, resources are created without this annotation, so the first invocation of <code>kubectl apply</code> will fall back to a two-way diff between the provided input and the current configuration of the resource. During this first invocation, it cannot detect the deletion of properties set when the resource was created. For this reason, it will not remove them.</p>

<p>All subsequent calls to <code>kubectl apply</code>, and other commands that modify the configuration, such as <code>kubectl replace</code> and <code>kubectl edit</code>, will update the annotation, allowing subsequent calls to <code>kubectl apply</code> to detect and perform deletions using a three-way diff.</p>

<blockquote class="note">
  <div><strong>Note:</strong> To use apply, always create resource initially with either <code>kubectl apply</code> or <code>kubectl create --save-config</code>.</div>
</blockquote>

<h3 id="kubectl-edit">kubectl edit</h3>

<p>Alternatively, you may also update resources with <code>kubectl edit</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl edit deployment/my-nginx</code></pre></div>
<p>This is equivalent to first <code>get</code> the resource, edit it in text editor, and then <code>apply</code> the resource with the updated version:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deployment my-nginx -o yaml &gt; /tmp/nginx.yaml
$ vi /tmp/nginx.yaml
<span style="color:#080;font-style:italic"># do some edit, and then save the file
</span><span style="color:#080;font-style:italic"></span>$ kubectl apply -f /tmp/nginx.yaml
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> configured
$ rm /tmp/nginx.yaml</code></pre></div>
<p>This allows you to do more significant changes more easily. Note that you can specify the editor with your <code>EDITOR</code> or <code>KUBE_EDITOR</code> environment variables.</p>

<p>For more information, please see <a href="../../../reference/generated/kubectl/kubectl-commands/index.html#edit">kubectl edit</a> document.</p>

<h3 id="kubectl-patch">kubectl patch</h3>

<p>You can use <code>kubectl patch</code> to update API objects in place. This command supports JSON patch,
JSON merge patch, and strategic merge patch. See
<a href="../../../tasks/run-application/update-api-object-kubectl-patch/index.html">Update API Objects in Place Using kubectl patch</a>
and
<a href="../../../reference/generated/kubectl/kubectl-commands/index.html#patch">kubectl patch</a>.</p>

<h2 id="disruptive-updates">Disruptive updates</h2>

<p>In some cases, you may need to update resource fields that cannot be updated once initialized, or you may just want to make a recursive change immediately, such as to fix broken pods created by a Deployment. To change such fields, use <code>replace --force</code>, which deletes and re-creates the resource. In this case, you can simply modify your original configuration file:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl replace -f docs/concepts/cluster-administration/nginx/nginx-deployment.yaml --force
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> deleted
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> replaced</code></pre></div>
<h2 id="updating-your-application-without-a-service-outage">Updating your application without a service outage</h2>

<p>At some point, you&rsquo;ll eventually need to update your deployed application, typically by specifying a new image or image tag, as in the canary deployment scenario above. <code>kubectl</code> supports several update operations, each of which is applicable to different scenarios.</p>

<p>We&rsquo;ll guide you through how to create and update applications with Deployments. If your deployed application is managed by Replication Controllers,
you should read <a href="../../../tasks/run-application/rolling-update-replication-controller/index.html">how to use <code>kubectl rolling-update</code></a> instead.</p>

<p>Let&rsquo;s say you were running version 1.7.9 of nginx:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl run my-nginx --image<span style="color:#666">=</span>nginx:1.7.9 --replicas<span style="color:#666">=</span><span style="color:#666">3</span>
deployment <span style="color:#b44">&#34;my-nginx&#34;</span> created</code></pre></div>
<p>To update to version 1.9.1, simply change <code>.spec.template.spec.containers[0].image</code> from <code>nginx:1.7.9</code> to <code>nginx:1.9.1</code>, with the kubectl commands we learned above.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl edit deployment/my-nginx</code></pre></div>
<p>That&rsquo;s it! The Deployment will declaratively update the deployed nginx application progressively behind the scene. It ensures that only a certain number of old replicas may be down while they are being updated, and only a certain number of new replicas may be created above the desired number of pods. To learn more details about it, visit <a href="../../workloads/controllers/deployment/index.html">Deployment page</a>.</p>














<h2 id="what-s-next">What&#39;s next</h2>
<ul>
<li><a href="../../../tasks/debug-application-cluster/debug-application-introspection/index.html">Learn about how to use <code>kubectl</code> for application introspection and debugging.</a></li>
<li><a href="../../configuration/overview/index.html">Configuration Best Practices and Tips</a></li>
</ul>






				<div class="issue-button-container">
					<p><a href="index.html"><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/concepts/cluster-administration/manage-deployment.md?pixel" alt="Analytics" /></a></p>
					
					
					<script type="text/javascript">
					PDRTJS_settings_8345992 = {
					"id" : "8345992",
					"unique_id" : "\/docs\/concepts\/cluster-administration\/manage-deployment\/",
					"title" : "Managing Resources",
					"permalink" : "https:\/\/kubernetes.io\/docs\/concepts\/cluster-administration\/manage-deployment\/"
					};
					(function(d,c,j){if(!document.getElementById(j)){var pd=d.createElement(c),s;pd.id=j;pd.src=('https:'==document.location.protocol)?'https://polldaddy.com/js/rating/rating.js':'http://i0.poll.fm/js/rating/rating.js';s=document.getElementsByTagName(c)[0];s.parentNode.insertBefore(pd,s);}}(document,'script','pd-rating-js'));
					</script>
					<a href="index.html" onclick="window.open('https://github.com/kubernetes/website/issues/new?title=Issue%20with%20' +
					'k8s.io'+window.location.pathname)" class="button issue">Create an Issue</a>
					
					
					
					<a href="../../../editdocs#docs/concepts/cluster-administration/manage-deployment.md" class="button issue">Edit this Page</a>
					
				</div>
			</div>
		</section>
		<footer>
    <main class="light-text">
        <nav>
            
            
            
            <a href="../../../home.1">Documentation</a>
            
            <a href="../../../../blog/index.html">Blog</a>
            
            <a href="../../../../partners/index.html">Partners</a>
            
            <a href="../../../../community/index.html">Community</a>
            
            <a href="../../../../case-studies/index.html">Case Studies</a>
            
        </nav>
        <div class="social">
            <div>
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
            </div>
            <div>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
            <div>
                <a href="../../../getting-started-guides/index.html" class="button">Get Kubernetes</a>
                <a href="https://git.k8s.io/community/contributors/guide" class="button">Contribute</a>
            </div>
        </div>
        <div id="miceType" class="center">
            &copy; 2018 The Kubernetes Authors | Documentation Distributed under <a href="https://git.k8s.io/website/LICENSE" class="light-text">CC BY 4.0</a>
        </div>
        <div id="miceType" class="center">
            Copyright &copy; 2018 The Linux Foundation&reg;. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a href="https://www.linuxfoundation.org/trademark-usage" class="light-text">Trademark Usage page</a>
        </div>
    </main>
</footer>

		<button class="flyout-button" onclick="kub.toggleToc()"></button>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36037335-10', 'auto');
ga('send', 'pageview');


(function () {
    window.addEventListener('DOMContentLoaded', init)

        
        function init() {
            window.removeEventListener('DOMContentLoaded', init)
                hideNav()
        }

    function hideNav(toc){
        if (!toc) toc = document.querySelector('#docsToc')
        if (!toc) return
            var container = toc.querySelector('.container')

                
                if (container) {
                    if (container.childElementCount === 0 || toc.querySelectorAll('a.item').length === 1) {
                        toc.style.display = 'none'
                            document.getElementById('docsContent').style.width = '100%'
                    }
                } else {
                    requestAnimationFrame(function () {
                        hideNav(toc)
                    })
                }
    }
})();
</script>



	</body>
</html>